package com.yy.comdemo.page

import android.content.Context
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.navigation.NavHostController
import com.baidu.mapapi.map.MapView

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BMapPage (navController: NavHostController?) {
    val context = LocalContext.current

    val searchKey by remember {
        mutableStateOf("")
    }

    val mapView = remember {
        MapView(context)
    }

    Box {
        AndroidView(factory = {
            mapView
        })
        Box(modifier = Modifier
            .align(Alignment.TopCenter)
            .padding(top = 70.dp)) {
            Card (
                colors = CardDefaults.cardColors(
                    containerColor = Color.White.copy(alpha = 0.9f)
                ),
                modifier = Modifier
                    .fillMaxWidth(0.95f)
            ) {
                OutlinedTextField(value = searchKey, onValueChange = {},
                    Modifier
                        .padding(vertical = 0.dp, horizontal = 5.dp)
                        .fillMaxWidth(), label = { Text(
                    text = "地址搜索"
                )}, singleLine = true)
                LazyColumn(modifier = Modifier.padding(horizontal = 10.dp), contentPadding = PaddingValues(bottom = 5.dp)) {

                }
            }
        }
        Box(modifier = Modifier
            .align(Alignment.BottomCenter)
            .fillMaxWidth(0.6f)
            .padding(bottom = 20.dp)) {
            Button(onClick = { /*TODO*/ }) {
                Text(text = "添加模拟地点", Modifier.fillMaxWidth(1f), textAlign = TextAlign.Center, letterSpacing = 1.2.sp, fontSize = 16.sp)
            }
        }
    }

//    Layout(measurePolicy = )

}

@Preview
@Composable
fun preView () {
    BMapPage(navController = null)
}